/*****************************************************
PROJECT: BRIDGE C2 SCRAP
JOB:
REQUESTOR:Rachel Gold
JIRA #:
ANALYST: Jean O'Malley
DATE: 8/4/2022
7/23/2023 corrected coding for orders within 1 year of due
corrected filtering for patients with 1 year observation after first due date
VERSION: 
LAST UPDATED: 
PEER REVIEWER: 

PROJECT DESCRIPTION: Use ASCEND approach to compare CRC, CVC and 
BC cancer prevention services in patients with
	No SDH Screening
	Documented Need
	Documented No Need
Stratified by SDH need: Food, Housing, Transportation
STUDY PERIOD: 7/1/2016-2/29/2020		

DETAILS (this file): 
CRC Outcome variables by SDH
	UTD at index 
	Type of last screen prior to index: None, FIT/FOBT, Imaging
	Months UTD over observation period
	Among Patients due 12 months before obs end, Receipt of screening order within 12 months
	Among patients with order, 
			receipt of order for imaging 
			receipt of screen while due(Poisson with months after due as offset)
		  	Receipt of FIT/FOBT order
			Receipt of Imaging/Order
Table 2.Columns Food Insecurity: Need/ No Need/ Not documented
Table 3 Columns Housing Insecurity: Need/ No Need/ Not documented
Table 4 Columns Transportation Insecurity: Need/ No Need/ Not documented
		

INPUT DATA:
SCRAP.CRC_outcomes;

OUTPUT DATA:
SCRAP.CRC_Table2_Food
SCRAP.CRC_Table3_Housing
SCRAP.CRC_Table4_Transportation


SECTIONS:
A. Dynamic variables and analysis file
B. Full cohort variables-this section was not rerun 7/26/2023
	B1. UTD at index 
	B2. Imaging screen prior to index: 
	B3. Months UTD over observation period
	B4. Visits in year following Index (includes index visit

C.Among Patients due 12 months before obs end > filtering on this section corrected 
	C1.Receipt of any screening order within 12 months

D.Among patients with order, 
	D1. receipt of screen while due(Poisson with months after due as offset)


****************************************************/
options compress=yes reuse=yes spool;
libname SCRAP "e:\\sasroot\BRIDGE C2\SCRAP\";
libname RD odbc noprompt="dsn=research_dev;Trusted_Connection=yes" bulkload=yes;

/****************************************************/
/***************************************************
A. Dynamic variables and analysis file
***************************************************/
%let cancer=CRC;
%Let covariates=female race_ethnic2 language_c  FPL_cat2 age_cat payor_type_research visit_cat;
%Let class=delivery_site_id female age_cat race_ethnic2 language_c  FPL_cat2 visit_cat payor_type_research;


data scrap.&cancer._analysis;
set SCRAP.&cancer._analysis;
sdh_trans=sdh_transportation;
if one_year_due<=observation_end and one_year_due^=. then do;
	order_1y_corrected=order_date2^=. and order_date2<one_year_due;
	screen_1yr_corrected=first_screen_date^=. and first_screen_date<one_year_due;
	order_6m_corrected=order_date2^=. and order_date< intnx('month',first_due_date,6,'same');
end;
run;
/*proc freq data=scrap.&cancer._analysis;*/
/*tables screen_1yr_corrected*screen_1yr;*/
/*run;*/




data analysis;
set SCRAP.&cancer._analysis;
run;




proc sort data=analysis;
by delivery_site_id;
run;
/*proc freq data=analysis;*/
/*tables due female race_ethnic2 language_c  FPL_cat2 age_cat payor_type_research visit_cat;*/
/*run;*/

%macro tables;
/********************************************************
/*C.Among Patients due 12 months before obs end, */
*********************************************************/;
data analysis2;
set analysis;
where one_year_due^=. and observation_end>=one_year_due;
run;


/*	C1.Receipt of any screening order within 12 months*/

	proc genmod data=analysis2 descending;
	class &class &sdh /ref=first;
	model order_1y_corrected=&sdh &covariates/link=log d=binomial type3;
	repeated subject=delivery_site_id/type=exch;
	LSmeans &sdh/ilink CL diff OM;
	ods output LSmeans=order_&sdh lsmestimates=order_diffs_&sdh;
	lsmestimate &sdh '1 vs 2' -1 0 1/cl  om ilink;
	lsmestimate &sdh '3 vs 2' -1 1 0 /cl   om ilink;
	run;
/*	proc genmod data=analysis2 descending;*/
/*	class &class &sdh /ref=first;*/
/*	model order_6m_corrected=&sdh &covariates/link=log d=binomial type3;*/
/*	repeated subject=delivery_site_id/type=exch;*/
/*	LSmeans &sdh/ilink CL diff OM;*/
/*	ods output LSmeans=order_&sdh lsmestimates=order_diffs_&sdh;*/
/*	lsmestimate &sdh '1 vs 2' -1 0 1/cl  om ilink;*/
/*	lsmestimate &sdh '3 vs 2' -1 1 0 /cl   om ilink;*/
/*	run;*/

/******************************************
/*D.Among patients with order, */
/******************************************/;
	data analysis3;
	set analysis2;
	where order_1y_corrected=1;
	run;

/*	D2. receipt of any screen*/
	
	proc genmod data=analysis3 descending;
	class &class &sdh /ref=first;
	model screen_1yr_corrected=&sdh &covariates/link=log d=binomial type3;
	repeated subject=delivery_site_id/type=exch;
	LSmeans &sdh/ilink CL OM;
	ods output LSmeans=screen_&sdh lsmestimates=screen_diffs_&sdh;
	lsmestimate &sdh '1 vs 2' -1 0 1/cl  om ilink;
	lsmestimate &sdh '3 vs 2' -1 1 0 /cl   om ilink;
	run;


%mend;

%let SDH=SDH_Food; 
%tables;


%let SDH=SDH_Housing;
%tables;

%Let SDH=SDH_Trans;
%tables;
proc datasets library=work;
save analysis;
quit;

proc freq data=scrap.crc_analysis;
where one_year_due^=. and observation_end>=one_year_due;
tables SDH_food--sdh_transportation;
run;

proc freq data=scrap.crc_analysis;
where one_year_due^=. and observation_end>=one_year_due
and order_1y_corrected=1;
tables SDH_food--sdh_transportation;
run;

